<template>
  <div>
    <h2>人数统计</h2>
    <div id="chart-one" class="one"></div>
  </div>
</template>

<script setup>
import { inject, onMounted, reactive } from "vue";
import link from "@/api/link.js";
import apiUrl from "@/api/url.js";
let $echarts = inject("echarts");
let data = reactive({});
let xdata = reactive([]);
let ydata = reactive([]);

onMounted(() => {
  let myChart = $echarts.init(document.getElementById("chart-one"));

  link(apiUrl.chartDataI).then((resolve) => {
    let { data } = resolve;
    xdata = data.map((x) => x.title);
    ydata = data.map((y) => y.number);
    myChart.setOption({
      xAxis: {
        type: "value",
        axisLine: {
          lineStyle: {
            color: "#fff",
          },
        },
      },
      yAxis: {
        type: "category",
        data: xdata,
        axisLine: {
          lineStyle: {
            color: "#fff",
          },
        },
      },
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      series: [
        {
          type: "bar",
          data: ydata,
          itemStyle: {
            normal: {
              barBorderRadius: [0, 20, 20, 0],
              color: new $echarts.graphic.LinearGradient(0, 0, 1, 0, [
                {
                  offset: 0,
                  color: "#005eaa",
                },
                {
                  offset: 0.5,
                  color: "#339ca8",
                },
                {
                  offset: 1,
                  color: "#cda819",
                },
              ]),
            },
          },
        },
      ],
    });
  });
});
</script>

<style scoped lang="scss">
h2 {
  height: 0.6rem;
  color: #fff;
  line-height: 0.6rem;
  text-align: center;
  font-size: 0.25rem;
}
.one {
  height: 6.3rem;
}
</style>
